// 登录处理
if (localStorage.getItem("id") && localStorage.getItem("token")) {
    $.ajax({
        url: "http://localhost:8888/users/info",
        method: "get",
        data: {
            id: localStorage.getItem("id")
        },
        headers: {
            authorization: localStorage.getItem("token")
        },
        success: function (res) {
            console.log(res);
            if (res.code === 1) {
                yonghu(res.info.nickname)
            }

            tuichu()
        }
    })

} else {
    console.log("没有");
}
function yonghu(a) {
    $(".header-left").html(`
    <span>您好! ${a} </span>
    <a href="login.html">退出</a>

    `)
}
function tuichu() {
    $(".header-left>a").on("click", function () {
        if (confirm("是否确定退出")) {
            $.ajax({
                url: "http://localhost:8888/users/logout",
                method: "get",
                headers: {
                    authorization: localStorage.getItem("token")
                },
                data: {
                    id: localStorage.getItem("id")
                },
                success: function (res) {
                    console.log(res);
                    alert(res.message)
                    location.href = "home.html"
                    localStorage.removeItem("id")
                    localStorage.removeItem("token")
                    localStorage.removeItem("gods_id")
                }
            })
        }
        return false
    })
}
// 个人信息跳转
$(".geren>p:nth-of-type(4)").on("click", function () {
    if (localStorage.getItem("id") && localStorage.getItem("token")) {
        location.href = `account.html`
    } else {
        alert("请先登录")
    }
    return false
})
// 分类列表
$.ajax({
    url: "http://localhost:8888/goods/category",
    method: "get",
    success: function (res) {
        arr = res.list
        for (var i = 1; i < 13; i++) {
            $(`<li>${arr[i]}</li>`)
            $(".left>ul").append($(`<li>${arr[i]}<b>&gt;</b></li>`))
        }
        $(".left>ul>li").on('click',function(){
            let str = $(this)[0].innerText.slice(0,$(this)[0].innerText.length-2)
            console.log(str);
            localStorage.setItem("category",str)
            localStorage.removeItem("value")
            location.href="list.html"
        })
    }
})
// 商品列表
var Src = ``
var arr = []
var brr = []
var Goode_id
// 鞋 
$.ajax({
    url: "http://localhost:8888/goods/list",
    method: "get",
    data: {
        search: "鞋",
    },
    success: function (res) {
        arr = res.list
        arr.forEach(function (item) {
            brr.push(item)
        })
        Src = res.list[5].img_big_logo
        Goode_id = res.list[5].goods_id
        box1()
    }
})

function box1() {
    $("section>.hot .box1>.left img").attr("src", Src).attr("gods_id", Goode_id)
    for (let i = 0; i < 4; i++) {
        $("section>.hot .box1> .center img")[i].setAttribute("src", `${brr[i].img_big_logo}`)
        $("section>.hot .box1> .center img")[i].setAttribute("gods_id", `${brr[i].goods_id}`)
    }
    $.ajax({
        url: "http://localhost:8888/goods/list",
        method: "get",
        data: {
            filter: "sale",
            search: "鞋",
        },
        success: function (res) {
            var str = res.list
            var index = 0
            var statr = 0
            var end = 4
            var olIndex = 0
            function Se() {
                for (var i = statr; i < end; i++) {
                    $("section>.hot .box1>.right>ul>li>div>del")[index].innerText = "￥" + `${str[i].current_price}`
                    $("section>.hot .box1>.right>ul>li>div>b")[index].innerText = "￥" + `${str[i].price}`
                    $("section>.hot .box1>.right>ul>li>div>a")[index].innerText = `${str[i].title}`
                    $("section>.hot .box1>.right>ul>li>div>img")[index].setAttribute("src", `${str[i].img_big_logo}`)
                    $("section>.hot .box1>.right>ul>li>div>img")[index].setAttribute("gods_id", `${str[i].goods_id}`)
                    index++
                }
            }
            Se()
            var timerId
            function timer() {
                timerId = setInterval(function () {
                    $("section>.hot .box1>.right div img").fadeOut(150)
                    $("section>.hot .box1>.right div img").fadeIn(150)
                    $("section>.hot .box1>.right div a").fadeOut(150)
                    $("section>.hot .box1>.right div a").fadeIn(150)
                    statr = end
                    end += 4
                    olIndex++
                    if (olIndex === 3) {
                        olIndex = 0
                        $("section>.hot .box1>.right>ol>li")[2].setAttribute("class", "")
                    } else {
                        $("section>.hot .box1>.right>ol>li")[olIndex - 1].setAttribute("class", "")
                    }
                    var index = 0
                    $("section>.hot .box1>.right>ol>li")[olIndex].setAttribute("class", "active")
                    console.log();
                    if (statr === 12) {
                        statr = 0
                        end = 4
                    }
                    for (var i = statr; i < end; i++) {
                        $("section>.hot .box1>.right>ul>li>div>del")[index].innerText = "￥" + `${str[i].current_price}`
                        $("section>.hot .box1>.right>ul>li>div>b")[index].innerText = "￥" + `${str[i].price}`
                        $("section>.hot .box1>.right>ul>li>div>a")[index].innerText = `${str[i].title}`
                        $("section>.hot .box1>.right>ul>li>div>img")[index].setAttribute("src", `${str[i].img_big_logo}`)
                        $("section>.hot .box1>.right>ul>li>div>img")[index].setAttribute("gods_id", `${str[i].goods_id}`)
                        index++
                    }
                }, 3000)
            }
            timer()
            $("section>.hot .box1>.right ul").hover(function () {
                clearInterval(timerId)
            }, function () {
                timer()
            })
            $("section>.hot .box1>.right ol").hover(function () {
                clearInterval(timerId)
                $("section>.hot .box1>.right ol>li").on("click", function (e) {
                    $(this).attr("class", "active").siblings().attr("class", "")
                    if (e.target === $("section>.hot .box1>.right ol>li")[1]) {
                        statr = 4
                        end = 8
                        index = 0
                        Se()
                        olIndex = 1
                    } else if (e.target === $("section>.hot .box1>.right ol>li")[2]) {
                        statr = 8
                        end = 12
                        index = 0
                        Se()
                        olIndex = 2
                    } else if (e.target === $("section>.hot .box1>.right ol>li")[0]) {
                        statr = 0
                        end = 4
                        index = 0
                        Se()
                        olIndex = 0
                    }
                })
            }, function () {
                timer()
            })
        }
    })
    $("section>.hot .box1 img").on("click", function () {
        console.log($(this).attr("gods_id"));
        localStorage.setItem("gods_id", $(this).attr("gods_id"))
        location.href = "data.html"
    })
    $("section>.hot .box1 dd").on("click", function () {
        console.log($(this).text());
        localStorage.setItem("search", $(this).text())
        location.href = "list.html"
    })
}
// 手表
var Src2 = ``
var arr2 = []
var brr2 = []
var Goode_id2
$.ajax({
    url: "http://localhost:8888/goods/list",
    method: "get",
    data: {
        search: "手表",
    },
    success: function (res) {
        arr2 = res.list
        arr2.forEach(function (item) {
            brr2.push(item)
        })
        Src2 = res.list[5].img_big_logo
        Goode_id2 = res.list[5].goods_id
        box2()
    }
})
function box2() {
    $("section>.hot .box2>.left img").attr("src", Src2).attr("gods_id", Goode_id2)
    for (let i = 0; i < 4; i++) {
        $("section>.hot .box2> .center img")[i].setAttribute("src", `${brr2[i].img_big_logo}`)
        $("section>.hot .box2> .center img")[i].setAttribute("gods_id", `${brr2[i].goods_id}`)
    }
    $.ajax({
        url: "http://localhost:8888/goods/list",
        method: "get",
        data: {
            // filter:"hot",
            search: "手表",
        },
        success: function (res) {
            var str2 = res.list
            console.log(str2);
            var index = 0
            var statr = 0
            var end = 4
            var olIndex = 0
            function Se() {
                for (var i = statr; i < end; i++) {
                    $("section>.hot .box2>.right>ul>li>div>del")[index].innerText = "￥" + `${str2[i].current_price}`
                    $("section>.hot .box2>.right>ul>li>div>b")[index].innerText = "￥" + `${str2[i].price}`
                    $("section>.hot .box2>.right>ul>li>div>a")[index].innerText = `${str2[i].title}`
                    $("section>.hot .box2>.right>ul>li>div>img")[index].setAttribute("src", `${str2[i].img_big_logo}`)
                    $("section>.hot .box2>.right>ul>li>div>img")[index].setAttribute("gods_id", `${str2[i].goods_id}`)
                    index++
                }
            }
            Se()
            var timerId2
            function timer2() {
                timerId2 = setInterval(function () {
                    $("section>.hot .box2>.right div img").fadeOut(150)
                    $("section>.hot .box2>.right div img").fadeIn(150)
                    $("section>.hot .box2>.right div a").fadeOut(150)
                    $("section>.hot .box2>.right div a").fadeIn(150)
                    statr = end
                    end += 4
                    olIndex++
                    if (olIndex === 3) {
                        olIndex = 0
                        $("section>.hot .box2>.right>ol>li")[2].setAttribute("class", "")
                    } else {
                        $("section>.hot .box2>.right>ol>li")[olIndex - 1].setAttribute("class", "")
                    }
                    var index = 0
                    $("section>.hot .box2>.right>ol>li")[olIndex].setAttribute("class", "active")
                    if (statr === 12) {
                        statr = 0
                        end = 4
                    }
                    for (var i = statr; i < end; i++) {
                        $("section>.hot .box2>.right>ul>li>div>del")[index].innerText = "￥" + `${str2[i].current_price}`
                        $("section>.hot .box2>.right>ul>li>div>b")[index].innerText = "￥" + `${str2[i].price}`
                        $("section>.hot .box2>.right>ul>li>div>a")[index].innerText = `${str2[i].title}`
                        $("section>.hot .box2>.right>ul>li>div>img")[index].setAttribute("src", `${str2[i].img_big_logo}`)
                        $("section>.hot .box2>.right>ul>li>div>img")[index].setAttribute("gods_id", `${str2[i].goods_id}`)
                        index++
                    }
                }, 3000)
            }
            timer2()
            $("section>.hot .box2>.right ul").hover(function () {
                clearInterval(timerId2)
            }, function () {
                timer2()
            })
            $("section>.hot .box2>.right ol").hover(function () {
                clearInterval(timerId2)
                $("section>.hot .box2>.right ol>li").on("click", function (e) {
                    $(this).attr("class", "active").siblings().attr("class", "")
                    if (e.target === $("section>.hot .box2>.right ol>li")[1]) {
                        statr = 4
                        end = 8
                        index = 0
                        Se()
                        olIndex = 1
                    } else if (e.target === $("section>.hot .box2>.right ol>li")[2]) {
                        statr = 8
                        end = 12
                        index = 0
                        Se()
                        olIndex = 2
                    } else if (e.target === $("section>.hot .box2>.right ol>li")[0]) {
                        statr = 0
                        end = 4
                        index = 0
                        Se()
                        olIndex = 0
                    }
                })
            }, function () {
                timer2()
            })
        }
    })
    $("section>.hot .box2 img").on("click", function () {
        console.log($(this).attr("gods_id"));
        localStorage.setItem("gods_id", $(this).attr("gods_id"))
        location.href = "data.html"
    })
    $("section>.hot .box2 dd").on("click", function () {
        console.log($(this).text());
        localStorage.setItem("search", $(this).text())
        location.href = "list.html"
    })
}
// 家电
var Src3 = ``
var arr3 = []
var brr3 = []
var Goode_id3
$.ajax({
    url: "http://localhost:8888/goods/list",
    method: "get",
    data: {
        search: "家电",
    },
    success: function (res) {
        arr3 = res.list
        arr3.forEach(function (item) {
            brr3.push(item)
        })
        Src3 = res.list[5].img_big_logo
        Goode_id3 = res.list[5].goods_id
        box3()
    }
})
function box3() {
    $("section>.hot .box3>.left img").attr("src", Src3).attr("gods_id", Goode_id3)
    for (let i = 0; i < 4; i++) {
        $("section>.hot .box3> .center img")[i].setAttribute("src", `${brr3[i].img_big_logo}`)
        $("section>.hot .box3> .center img")[i].setAttribute("gods_id", `${brr3[i].goods_id}`)
    }
    $.ajax({
        url: "http://localhost:8888/goods/list",
        method: "get",
        data: {
            // filter:"hot",
            search: "手机",
        },
        success: function (res) {
            var str3 = res.list
            console.log(str3);
            var index = 0
            var statr = 0
            var end = 4
            var olIndex = 0
            function Se() {
                for (var i = statr; i < end; i++) {
                    $("section>.hot .box3>.right>ul>li>div>del")[index].innerText = "￥" + `${str3[i].current_price}`
                    $("section>.hot .box3>.right>ul>li>div>b")[index].innerText = "￥" + `${str3[i].price}`
                    $("section>.hot .box3>.right>ul>li>div>a")[index].innerText = `${str3[i].title}`
                    $("section>.hot .box3>.right>ul>li>div>img")[index].setAttribute("src", `${str3[i].img_big_logo}`)
                    $("section>.hot .box3>.right>ul>li>div>img")[index].setAttribute("gods_id", `${str3[i].goods_id}`)
                    index++
                }
            }
            Se()
            var timerId3
            function timer3() {
                timerId3 = setInterval(function () {
                    $("section>.hot .box3>.right div img").fadeOut(150)
                    $("section>.hot .box3>.right div img").fadeIn(150)
                    $("section>.hot .box3>.right div a").fadeOut(150)
                    $("section>.hot .box3>.right div a").fadeIn(150)
                    statr = end
                    end += 4
                    olIndex++
                    if (olIndex === 3) {
                        olIndex = 0
                        $("section>.hot .box3>.right>ol>li")[2].setAttribute("class", "")
                    } else {
                        $("section>.hot .box3>.right>ol>li")[olIndex - 1].setAttribute("class", "")
                    }
                    var index = 0
                    $("section>.hot .box3>.right>ol>li")[olIndex].setAttribute("class", "active")
                    if (statr === 12) {
                        statr = 0
                        end = 4
                    }
                    for (var i = statr; i < end; i++) {
                        $("section>.hot .box3>.right>ul>li>div>del")[index].innerText = "￥" + `${str3[i].current_price}`
                        $("section>.hot .box3>.right>ul>li>div>b")[index].innerText = "￥" + `${str3[i].price}`
                        $("section>.hot .box3>.right>ul>li>div>a")[index].innerText = `${str3[i].title}`
                        $("section>.hot .box3>.right>ul>li>div>img")[index].setAttribute("src", `${str3[i].img_big_logo}`)
                        $("section>.hot .box3>.right>ul>li>div>img")[index].setAttribute("gods_id", `${str3[i].goods_id}`)
                        index++
                    }
                }, 3000)
            }
            timer3()
            $("section>.hot .box3>.right ul").hover(function () {
                clearInterval(timerId3)
            }, function () {
                timer3()
            })
            $("section>.hot .box3>.right ol").hover(function () {
                clearInterval(timerId3)
                $("section>.hot .box3>.right ol>li").on("click", function (e) {
                    $(this).attr("class", "active").siblings().attr("class", "")
                    if (e.target === $("section>.hot .box3>.right ol>li")[1]) {
                        statr = 4
                        end = 8
                        index = 0
                        Se()
                        olIndex = 1
                    } else if (e.target === $("section>.hot .box3>.right ol>li")[2]) {
                        statr = 8
                        end = 12
                        index = 0
                        Se()
                        olIndex = 2
                    } else if (e.target === $("section>.hot .box3>.right ol>li")[0]) {
                        statr = 0
                        end = 4
                        index = 0
                        Se()
                        olIndex = 0
                    }
                })
            }, function () {
                timer3()
            })
        }
    })
    $("section>.hot .box3 img").on("click", function () {
        console.log($(this).attr("gods_id"));
        localStorage.setItem("gods_id", $(this).attr("gods_id"))
        location.href = "data.html"
    })
    $("section>.hot .box3 dd").on("click", function () {
      
        location.href = "list.html"
    })
}
// 母婴
var Src4 = ``
var arr4 = []
var brr4 = []
var Goode_id4
$.ajax({
    url: "http://localhost:8888/goods/list",
    method: "get",
    data: {
        search: "儿童",
    },
    success: function (res) {
        arr4 = res.list
        arr4.forEach(function (item) {
            brr4.push(item)
        })
        Src4 = res.list[5].img_big_logo
        Goode_id4 = res.list[5].goods_id
        box4()
    }
})
function box4() {
    $("section>.hot .box4>.left img").attr("src", Src4).attr("gods_id", Goode_id4)
    for (let i = 0; i < 4; i++) {
        $("section>.hot .box4> .center img")[i].setAttribute("src", `${brr4[i].img_big_logo}`)
        $("section>.hot .box4> .center img")[i].setAttribute("gods_id", `${brr4[i].goods_id}`)
    }
    $.ajax({
        url: "http://localhost:8888/goods/list",
        method: "get",
        data: {
            // filter:"hot",
            search: "奶",
        },
        success: function (res) {
            var str4 = res.list
            var index = 0
            var statr = 0
            var end = 4
            var olIndex = 0
            function Se() {
                for (var i = statr; i < end; i++) {
                    $("section>.hot .box4>.right>ul>li>div>del")[index].innerText = "￥" + `${str4[i].current_price}`
                    $("section>.hot .box4>.right>ul>li>div>b")[index].innerText = "￥" + `${str4[i].price}`
                    $("section>.hot .box4>.right>ul>li>div>a")[index].innerText = `${str4[i].title}`
                    $("section>.hot .box4>.right>ul>li>div>img")[index].setAttribute("src", `${str4[i].img_big_logo}`)
                    $("section>.hot .box4>.right>ul>li>div>img")[index].setAttribute("gods_id", `${str4[i].goods_id}`)
                    index++
                }
            }
            Se()
            var timerId4
            function timer4() {
                timerId4 = setInterval(function () {
                    $("section>.hot .box4>.right div img").fadeOut(150)
                    $("section>.hot .box4>.right div img").fadeIn(150)
                    $("section>.hot .box4>.right div a").fadeOut(150)
                    $("section>.hot .box4>.right div a").fadeIn(150)
                    statr = end
                    end += 4
                    olIndex++
                    if (olIndex === 3) {
                        olIndex = 0
                        $("section>.hot .box4>.right>ol>li")[2].setAttribute("class", "")
                    } else {
                        $("section>.hot .box4>.right>ol>li")[olIndex - 1].setAttribute("class", "")
                    }
                    var index = 0
                    $("section>.hot .box4>.right>ol>li")[olIndex].setAttribute("class", "active")
                    if (statr === 12) {
                        statr = 0
                        end = 4
                    }
                    for (var i = statr; i < end; i++) {
                        $("section>.hot .box4>.right>ul>li>div>del")[index].innerText = "￥" + `${str4[i].current_price}`
                        $("section>.hot .box4>.right>ul>li>div>b")[index].innerText = "￥" + `${str4[i].price}`
                        $("section>.hot .box4>.right>ul>li>div>a")[index].innerText = `${str4[i].title}`
                        $("section>.hot .box4>.right>ul>li>div>img")[index].setAttribute("src", `${str4[i].img_big_logo}`)
                        $("section>.hot .box4>.right>ul>li>div>img")[index].setAttribute("gods_id", `${str4[i].goods_id}`)
                        index++
                    }
                }, 3000)
            }
            timer4()
            $("section>.hot .box4>.right ul").hover(function () {
                clearInterval(timerId4)
            }, function () {
                timer4()
            })
            $("section>.hot .box4>.right ol").hover(function () {
                clearInterval(timerId4)
                $("section>.hot .box4>.right ol>li").on("click", function (e) {
                    $(this).attr("class", "active").siblings().attr("class", "")
                    if (e.target === $("section>.hot .box4>.right ol>li")[1]) {
                        statr = 4
                        end = 8
                        index = 0
                        Se()
                        olIndex = 1
                    } else if (e.target === $("section>.hot .box4>.right ol>li")[2]) {
                        statr = 8
                        end = 12
                        index = 0
                        Se()
                        olIndex = 2
                    } else if (e.target === $("section>.hot .box4>.right ol>li")[0]) {
                        statr = 0
                        end = 4
                        index = 0
                        Se()
                        olIndex = 0
                    }
                })
            }, function () {
                timer4()
            })
        }
    })
    $("section>.hot .box4 img").on("click", function () {
        console.log($(this).attr("gods_id"));
        localStorage.setItem("gods_id", $(this).attr("gods_id"))
        location.href = "data.html"
    })
    $("section>.hot .box4 dd").on("click", function () {
        console.log($(this).text());
        localStorage.setItem("search", $(this).text())
        location.href = "list.html"
    })
}
// 列表页跳转
$("body>.box nav div .right li>a").on("click", function (e) {
    const Text = e.target.innerText
    if (Text === "海外职购") {
        localStorage.removeItem("value")
        localStorage.removeItem("category")
        location.href = "list.html"
    } else if (Text === "考拉海购出品" && localStorage.getItem("gods_id")) {
        location.href = "data.html"
    } else {
        $(this).attr("class", "active").parent().siblings().children().removeAttr("class")
    }
    return false
})
// 轮播图

var first = $("body>section>div:nth-of-type(1)>ul li:nth-of-type(1)").clone()
var end = $("body>section>div:nth-of-type(1)>ul li:nth-last-of-type(1)").clone()
var Index = 1
var open = true
var timer
for (var i = 0; i < $("body>section>div:nth-of-type(1)>ul").children().length; i++) {
    if (i == 0) {
        $("body>section>div:nth-of-type(1)>ol").append($("<li class='color'></li>"))
    } else {
        $("body>section>div:nth-of-type(1)>ol").append($("<li></li>"))
    }
}
$("body>section>div:nth-of-type(1)>ul").prepend(end).append(first)
$("body>section>div:nth-of-type(1)>ul").css({
    width: $("body>section>div:nth-of-type(1)>ul").children().length * $("body>section>div:nth-of-type(1)>ul img").width() + "px",
    left: -Index * $("body>section>div:nth-of-type(1)>ul li:nth-of-type(1)").width() + "px"
})
// 右按钮
$("body>section>div:nth-of-type(1)>span:nth-of-type(2)").on("click", function () {
    if (!open) {
        return
    }
    open = false
    Index++
    Color()
    $("body>section>div:nth-of-type(1)>ul").animate({
        left: -Index * $("body>section>div:nth-of-type(1)>ul li:nth-of-type(1)").width()
    }, 800, "swing", function () {
        Left()
    })
})
// 左按钮
$("body>section>div:nth-of-type(1)>span:nth-of-type(1)").on("click", function () {
    if (!open) {
        return
    }
    open = false
    Index--
    Color()
    $("body>section>div:nth-of-type(1)>ul").animate({
        left: -Index * $("body>section>div:nth-of-type(1)>ul li:nth-of-type(1)").width()
    }, 800, "swing", function () {
        Left()
    })
})
// 圆点点击
$("body>section>div:nth-of-type(1)>ol li").on("click", function () {
    if (!open) {
        return
    }
    open = false
    Index = 1 + $("body>section>div:nth-of-type(1)>ol").children().index($(this))
    Color()
    $("body>section>div:nth-of-type(1)>ul").animate({
        left: -Index * $("body>section>div:nth-of-type(1)>ul li:nth-of-type(1)").width()
    }, 800, "swing", function () {
        Left()
    })
})
// 定时器
timer = setInterval(function () {
    Index++
    Color()
    $("body>section>div:nth-of-type(1)>ul").animate({
        left: -Index * $("body>section>div:nth-of-type(1)>ul li:nth-of-type(1)").width()
    }, 800, "swing", function () {
        Left()
    })
}, 5000)
// 移入移出
$("body>section>div:nth-of-type(1)").hover(function () {
    $("body>section>div:nth-of-type(1)>span").css({
        display: "block",
    })
    clearInterval(timer)
}, function () {
    $("body>section>div:nth-of-type(1)>span").css({
        display: "none",
    })
    timer = setInterval(function () {
        Index++
        Color()
        $("body>section>div:nth-of-type(1)>ul").animate({
            left: -Index * $("body>section>div:nth-of-type(1)>ul li:nth-of-type(1)").width()
        }, 800, "swing", function () {
            Left()
        })
    }, 5000)
})
// 处理原点函数
function Color() {
    if (Index == $("body>section>div:nth-of-type(1)>ul").children().length - 1) {
        Index = 1
        $("body>section>div:nth-of-type(1)>ol li").removeAttr("class")
        $(`body>section>div:nth-of-type(1)>ol li`)[Index - 1].setAttribute("class", "color")
        Index = $("body>section>div:nth-of-type(1)>ul").children().length - 1
    } else if (Index == 0) {
        Index = $("body>section>div:nth-of-type(1)>ul").children().length - 2
        $("body>section>div:nth-of-type(1)>ol li").removeAttr("class")
        $(`body>section>div:nth-of-type(1)>ol li`)[Index - 1].setAttribute("class", "color")
        Index = 0
    } else {
        console.log(123);
        $("body>section>div:nth-of-type(1)>ol li").removeAttr("class")
        $(`body>section>div:nth-of-type(1)>ol li`)[Index - 1].setAttribute("class", "color")
    }
}
// 处理left距离函数
function Left() {
    if (Index === $("body>section>div:nth-of-type(1)>ul").children().length - 1) {
        Index = 1
        $("body>section>div:nth-of-type(1)>ul").css({
            left: -Index * $("body>section>div:nth-of-type(1)>ul li:nth-of-type(1)").width() + "px"
        })
    } else if (Index === 0) {
        Index = $("body>section>div:nth-of-type(1)>ul").children().length - 2
        $("body>section>div:nth-of-type(1)>ul").css({
            left: -Index * $("body>section>div:nth-of-type(1)>ul li:nth-of-type(1)").width() + "px"
        })
    }
    open = true
}
// 
$("section>.hot>.right div span").on("click", function (e) {
    console.log();
    if (e.target.innerText === "购物车") {
        location.href = "cart.html"
    } else if (e.target.innerText === "Top") {
        document.documentElement.scrollTop = 0
    }
})
// 搜索内容
$("nav section .search .box div input").on("input", function () {
    $("nav section .search span").on("click",function(){
        let value = $("nav section .search .box div input")[0].value
        localStorage.setItem("value",value)
        console.log(value);
        setTimeout(function(){
            $("nav section .search .box div input")[0].value = ``
        },500)
        location.href="list.html"
    })
    $("body").on("keydown",function(e){
        if(e.keyCode===13){
            let value = $("nav section .search .box div input")[0].value
            localStorage.setItem("value",value)
            setTimeout(function(){
                $("nav section .search .box div input")[0].value = ``
            },500)
            localStorage.removeItem("category")
            location.href="list.html"
        }
    })
})

